<template>
  <view>
    <view class="content-view">
      <uni-card :border="false">
        <view class="title">
          收费组成（电费+服务费+占仓费）
        </view>
        <costType :form="dataDetail"></costType>
      </uni-card>
    </view>
  </view>
</template>

<script>
  import {
    chargingCabinet,
    createOrder
  } from '@/api/equip.js';
  import costType from "@/components/costType.vue";

  export default {
    components: {
      costType
    },
    data() {
      return {
        code: '', //充电柜编码
        dataDetail: {},
        orderId: '', //订单ID
        chargeTmplPriceId: "", //模板id
      }
    },
    onLoad(option) {
      this.code = option.code || "";
      this.orderId = option.orderId || "";
      this.chargeTmplPriceId = option.chargeTmplPriceId || "";
      if (this.chargeTmplPriceId) {
        this.getOrderRule();
      } else if (this.code) {
        this.getDataList();
      }
    },
    methods: {
      getDataList() {
        this.$Toast.loading('加载中');
        chargingCabinet('/selectAllData', 'get', {
          code: this.code
        }).then(res => {
          uni.hideLoading();
          if (res.code == 200) {
            let datas = res.data.chargeTmpl;
            datas.duration = datas.chargeTmplPriceList.filter(item => item.type == 'DURATION'); //按时
            datas.quantity = datas.chargeTmplPriceList.filter(item => item.type == 'QUANTITY'); //按量

            this.dataDetail = datas;
          }
        }).catch(err => {})
      },
      getOrderRule() {
        this.$Toast.loading('加载中');
        createOrder('/order/billing/detail', 'get', {
          chargeTmplPriceId: this.chargeTmplPriceId
        }).then(res => {
          uni.hideLoading();
          let datas = res.data;
          let {
            price,
            serviceFee,
            type,
            unit,
          } = datas;
          if (datas.type == 'DURATION') {
            datas.duration = [{
              price,
              serviceFee,
              type,
              unit,
            }];
          } else if (datas.type == 'QUANTITY') {
            datas.quantity = [{
              price,
              serviceFee,
              type,
              unit,
            }];
          }
          this.dataDetail = datas;
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  @import "@/static/css/common.scss";

  .switchHead {
    border: 1px solid #3672a0;
    border-radius: 10rpx;
    line-height: 60rpx;
    color: #3672a0;
    margin-bottom: 8rpx;
    @include flexLayout(center, space-between);

    view {
      width: 50%;
      text-align: center;
    }

    .activeCss {
      background: #3672a0;
      color: #FFFFFF;
    }
  }

  page {
    background-color: #f7f7f7;
  }

  .title {
    font-size: 30upx;
    color-profile: #393939;
    font-weight: bold;
  }

  .content-view {
    margin: 0px 10px;

    .table {
      width: 100%;
      margin-top: 30upx;

      .table-title {
        display: flex;
        align-items: center;

        view {
          width: 100%;
          text-align: center;
          background-color: #eff8ff;
          color: #3672a0;
        }

        view:nth-child(1) {
          border-radius: 10upx 0 0 0;
        }

        view:nth-child(2) {
          border-radius: 0 10upx 0 0;
        }
      }

      .time {
        display: flex;
        align-items: stretch;

        .time-slot {
          // width: 50%;
          // height: 100%;
          // text-align: center;
          // background-color: #eff8ff;
          // border: 2upx solid #fff;
          width: 50%;
          text-align: center;
          background-color: #eff8ff;
          border: 2rpx solid #fff;
        }

        .fillet1 {
          border-radius: 0 0 0 10upx;
        }

        .fillet2 {
          view:nth-child(2) {
            border-radius: 0 0 10upx 0;
          }
        }
      }
    }
  }

  .time-node {
    display: inline-block;
    width: 100%;
    text-align: center;
    background-color: #eff8ff;
    height: 98upx;
    line-height: 100upx;
    border: 2upx solid #fff;

    text {
      width: 50%;
      display: inline-block;
      height: 98upx;
      line-height: 100upx;
      border: 2upx solid #fff;
      box-sizing: border-box;
    }
  }

  .info {
    margin-left: 10upx;
    margin-top: 20upx;
    color: #393939;
    font-size: 26upx;
    margin-bottom: 90upx;
  }

  /deep/ .uni-card {
    padding: 10px !important;
  }

  /deep/ .uni-table-tr {
    display: block !important;
    width: 100% !important;
    background-color: #EFF8FF !important;
    color: #346D9C !important;
    border: 1px solid #FFFFFF !important;
  }

  /deep/ .uni-table-td {
    display: block !important;
    width: 100% !important;
    color: #000000 !important;
    border: 1px solid #FFFFFF !important;
    padding: 5px !important;
    vertical-align: middle !important;
  }

  /deep/ .uni-table-th {
    display: block !important;
    width: 100% !important;
    color: #346D9C !important;
    border: 1px solid #FFFFFF !important;
    padding: 5px !important;
  }
</style>
